import 'dart:convert';

import 'package:kmxy_base/base/base_package.dart';
import 'package:kmxy_base/page/select_check/select_check_page_view.dart';

abstract class SelectCheckPageState extends BasePageState<SelectCheckPage> {
  List dataList = [];
  @override
  initData() async {
    List tempList = widget.arguments?['dataList'] ?? [];
    if (tempList.isEmpty) {
      '没有数据'.toast();
      return;
    }
    String tempListS = jsonEncode(tempList);
    dataList.clear();
    dataList.addAll(jsonDecode(tempListS));
    for (Map data in dataList) {
      data['isShow'] = true;
      data['check'] = false;
    }
    setState(() {});
  }

  @override
  destroyData() {}

  sure() {
    List sureList = [];
    for (Map data in dataList) {
      if (data['check']) {
        sureList.add(data);
      }
    }
    finishPop(context, callBackData: {'checkList': sureList});
  }

  search(String text) {
    for (Map data in dataList) {
      if (data[widget.arguments?['name']].contains(text)) {
        data['isShow'] = true;
      } else {
        data['isShow'] = false;
      }
    }
    setState(() {});
  }
}
